<?php
namespace app\yunda\admin;

use app\common\builder\ZBuilder;
use app\yunda\model\Message as MessageModel;
use app\yunda\model\User;
use think\Db;

/**
 * 投诉
 * @package app\yunda\admin
 */
class Message extends Base{
    public function index()
    {
        // 获取查询和排序规则
        $map = $this->getMap();
        $order = $this->getOrder();
        $data = Db::view('yd_message')
            ->view('yd_user','nickname','yd_user.openid=yd_message.openid')
            ->where($map)
            ->order($order)
            ->order('yd_message.id desc')
            ->paginate()->each(function($item){
                return $item;
            });
        //halt($data);
        return ZBuilder::make('table')
            ->setTableName('yd_message')  //需要修改 这里修改正确可以直接修改字段 删除
            ->addColumns([
                ['id','id'],
                ['nickname','反馈用户'],
                ['phone','电话'],
                ['content','反馈意见'],
                ['create_time','创建时间','datetime'],
                ['right_button', '操作', 'btn']
            ])
//            ->addTopButton('add', [],[])
//            ->addRightButton('edit',[],[])
            ->addTopButtons(['delete'])
            ->setRowList($data)
            ->addFilter(['nickname' => 'yd_user'])
            ->setSearch([ 'phone' => '电话'])
            ->fetch();
    }


    public function edit($id=null){
        if($this->request->isPost()){
            $data = request()->post();
            MessageModel::update($data);
            $this->success('保存成功', null, '_parent_reload');
        }
        $data = MessageModel::get($id);
        return ZBuilder::make('form')
            ->addFormItems([
                ['hidden','id'],  // 多增加一个影藏ID 即可
                ['raido','is_use','是否采纳','',['否','是'],0],
            ])
            ->setFormData($data)
            ->fetch();
    }
}